package org.coody.gitee.fuzzer;

import java.text.MessageFormat;

import org.coody.gitee.entity.GiteeEntity;
import org.coody.gitee.exception.FuzzerException;
import org.coody.gitee.fuzzer.iface.GiteeFuzzer;
import org.coody.gitee.util.HttpUtil;
import org.coody.gitee.util.HttpUtil.HttpEntity;

public class GiteeForkFuzzer extends GiteeFuzzer {

	@Override
	public void fuzzer(GiteeEntity giteeEntity) throws FuzzerException {
		for (String project : giteeEntity.getProjects()) {
			String postData = MessageFormat.format("authenticity_token={0}&members=&namespace_path={1}",
					giteeEntity.getCsrfToken(), giteeEntity.getSpace());
			String forkUrl = "https://gitee.com/" + giteeEntity.getSpace() + "/fork_project/"
					+ project.replace("https://gitee.com", "");
			HttpEntity entity = HttpUtil.Post(forkUrl, postData, "utf-8", giteeEntity.getCookie(),
					giteeEntity.buildHeader());
			System.out.println("Fork>>" + giteeEntity.getEmail() + ":" + entity.getHtml());
		}
	}

}
